/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.authorization.manager;

import javax.servlet.http.HttpServletRequest;

/**
 * 对Token进行操作的接口
 *
 * @author bifrost
 * @version 1.0.0
 * @Date 2017/10/9 10:50
 */
public interface TokenManager {
    /**
     * 创建一个token关联上指定用户
     *
     * @param userId 指定用户的id
     * @return 生成的token
     */
    public String createToken(long userId);

    /**
     * 检查token是否有效,有效时则将id存入request
     *
     * @param token 待验证的token
     * @return 是否有效
     */
    public boolean checkToken(String token, HttpServletRequest request);

    /**
     * 从字符串中解析token
     *
     * @param authentication 加密后的字符串
     * @return
     */
    public String getToken(String authentication);

    /**
     * 清除token
     *
     * @param userId 登录用户的id
     */
    public void deleteToken(long userId);
}
